/* vim: set sw=8 ts=8 sts=8 expandtab: */
#ifndef CMAID_MAP_FUNCDEF_H
#define CMAID_MAP_FUNCDEF_H

/**
 * @def CMAID_MAP_FUNC(c)
 * @ingroup Cmaid_Map_Interface
 * Macro to access the map interface.
 */
#define CMAID_MAP_FUNC(c) ((const Cmaid_Map_Interface *)((c)->interface))

/**
 * @param m The map to associate key and value
 * @param key The key
 * @param value The data
 * @return Returns the address of the saved key
 * @brief Associates the given @p key with the give @p value
 *
 * This functions associates the given @p key with the @p value. If there is
 * not already a node, a new node will be added to the collection. If the
 * @p key has already an entry in the collection the old value will be 
 * overwritten by the new value.
 */
CMAID_INLINE void *
cmaid_map_set(Cmaid_Map *m, const void *key, const void *value)
{
        return CMAID_MAP_FUNC(m)->set(m, key, value);
}

/**
 * @param m The map to remove the key-value pair
 * @param key The key to remove
 * @return Returns no value
 * @brief Removes the key-value pair from the map
 *
 * This functions removes the key-value pair from the map and frees if needed
 * the memory of them. If the key is not part of the map nothing will happen.
 */
CMAID_INLINE void
cmaid_map_remove(Cmaid_Map *m, const void *key)
{
        CMAID_MAP_FUNC(m)->remove(m, key);
}

/**
 * @param m The map to retrieve the value associated with the given @p key
 * @param key The key associated with the desired value
 * @return Returns the value associated with the given @p key
 *
 * This functions returns the value associated with the given @p key. If there
 * is no value associated with it @c NULL will be returned.
 */
CMAID_INLINE void *
cmaid_map_get(Cmaid_Map *m, const void *key)
{
        return CMAID_SET_FUNC(m)->get(m, key);
}

/**
 * @param m The map to attach the iterator
 * @param iter The iterator to attach
 * @return Returns no value
 * @brief Attaches an iterator to iterate over the values
 *
 * This function attaches an iterator to the map. Unlike the normal container
 * iterator it will not iterate over the keys, but over the values of the map.
 * To detach the iterator from the map use the container function
 * cmaaid_container_iter_detach().
 */
CMAID_INLINE void
cmaid_map_value_iter_attach(Cmaid_Map *m, Cmaid_Iter *iter)
{
        CMAID_MAP_FUNC(m)->value_iter_attach(m, iter);
}

#endif
